package com.java.digitalsignagesystem.controller;
import com.java.digitalsignagesystem.entity.Indicator;
import com.java.digitalsignagesystem.entity.Result;
import com.java.digitalsignagesystem.service.IndicatorService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * (Indicator)表控制层
 *
 * @author makejava
 * @since 2023-08-25 09:49:42
 */
@RestController
@RequestMapping("/indicator")
public class IndicatorController {
    @Autowired
    IndicatorService indicatorService;


    /**
     * 新增数据
     *
     * @param indicator 实体
     * @return 新增结果
     */
    //@ApiOperation("新增专题")
    @PostMapping("/add")
    public Result add(@RequestBody Indicator indicator)  {
        for (int i=0;i<indicator.getCodes().size();i++){
            Indicator indicator1 = new Indicator();
            BeanUtils.copyProperties(indicator,indicator1);
            indicator1.setCode(indicator.getCodes().get(i));
            indicatorService.save(indicator1);
        }
        return Result.success("新增成功");
    }


    //@ApiOperation("根据theme名称删除新增的专题")
    @DeleteMapping("/delete")
    public Result deleteById(@RequestParam String theme) {
        indicatorService.deleteByTheme(theme);
        return Result.success("删除成功");
    }

    //@ApiOperation("根据用户的ID来查询新增专题")
    @GetMapping("/list")
    public Result getByUserId(@RequestParam("id") String id){
        List<Indicator> byUserId = indicatorService.getByUserId(id);
        return Result.success(byUserId);
    }



}

